/**
 * @param instance 实例
 * @param key 属性名
 */
function instanceDecorator(instance: InstanceType<any>, key: any) {
  // console.log("instance ", instance);
  // console.log("key2 ", key);
}

/**
 * 不传参
 * @param target 实例
 * @param key 属性名
 * @param descriptor 属性描述符
 */
function readOnly(target: any, key: string, descriptor: PropertyDescriptor) {
  descriptor.writable = false
}

// 传参
function configurable(val: boolean) {
  return function (target: any, key: string, descriptor: PropertyDescriptor) {
    descriptor.configurable = val
  }
}

class PropertyDescribe {
  // 等同于 instanceDecorator(this, "_name");
  @instanceDecorator
  _name = '张三'
  _age = 20

  // 等同于 Object.defineProperty(this, "getName", { writable: false });
  @readOnly
  getName() {
    return this._name
  }

  // 等同于 Object.defineProperty(this, "getAge", { configurable: false });
  @configurable(false)
  getAge() {
    return this._age
  }
}

const pdd = new PropertyDescribe()

// @ts-ignore
console.log(Object.getOwnPropertyDescriptor(pdd.__proto__, 'getName'))
// @ts-ignore
console.log(Object.getOwnPropertyDescriptor(pdd.__proto__, 'getAge'))
